package demo04;

import java.util.*;

public class DouDiZhu {
    public static void main(String[] args) {
        //1.准备牌
        ArrayList<String> preparePoker = preparePoker();
        HashMap<String, ArrayList<String>> hashMap = new HashMap<>();
        //2.洗牌
        Collections.shuffle(preparePoker);
//        System.out.println(preparePoker);
        //3.发牌
        sendPoker(preparePoker, hashMap);
        //4.显示牌
/*        Iterator<Map.Entry<String, ArrayList<String>>> iterator = hashMap.entrySet().iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }*/
        hashMap.entrySet().forEach(poker -> System.out.println(poker));
    }

    private static void sendPoker(ArrayList<String> arrayList, HashMap<String, ArrayList<String>> hashMap) {
        ArrayList<String> poker1 = new ArrayList<>();
        ArrayList<String> poker2 = new ArrayList<>();
        ArrayList<String> poker3 = new ArrayList<>();
        ArrayList<String> diPai = new ArrayList<>();
        for (int i = 0; i < arrayList.size(); i++) {
            if (i > 50) {
                diPai.add(arrayList.get(i));
            }
            else {
                if (i % 3 == 0) {
                    poker1.add(arrayList.get(i));
                }
                if (i % 3 == 1) {
                    poker2.add(arrayList.get(i));

                }
                if (i % 3 == 2) {
                    poker3.add(arrayList.get(i));
                }
            }

        }
/*        Collections.sort(poker1);
        Collections.sort(poker2);
        Collections.sort(poker3);
        Collections.sort(diPai);*/
        hashMap.put("夏同学", poker1);
        hashMap.put("李同学", poker2);
        hashMap.put("石同学", poker3);
        hashMap.put("底牌", diPai);
    }

    private static ArrayList<String> preparePoker() {
        ArrayList<String> huashe = new ArrayList<>();
        Collections.addAll(huashe, "♠", "♥", "♣", "♦");
        ArrayList<String> shuzi = new ArrayList<>();
        Collections.addAll(shuzi, "2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3");
        ArrayList<String> zhuzhuang = new ArrayList<>();


        for (int i = 0; i < huashe.size(); i++) {
            for (int j = 0; j < shuzi.size(); j++) {
                zhuzhuang.add(huashe.get(i) + shuzi.get(j));
            }
        }
        Collections.addAll(zhuzhuang, "大王", "小王");
        return zhuzhuang;
    }

}
